package com.zmn.plat.services.impl.message;

import java.util.Objects;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.plat.model.entity.message.MsgBaiduTemplate;
import com.zmn.plat.persistence.interfaces.message.MsgBaiduTemplateDAO;
import com.zmn.plat.services.interfaces.message.MsgBaiduTemplateService;

import lombok.extern.slf4j.Slf4j;

/**
 * 描述: 模板消息百度小程序模板配置基础接口实现类
 *
 * @author wangjie date 2020/7/9 14:27
 **/
@Slf4j
@Service
public class MsgBaiduTemplateServiceImpl implements MsgBaiduTemplateService {

    @Resource
    private MsgBaiduTemplateDAO msgBaiduTemplateDAO;

    @Override
    public MsgBaiduTemplate findById(Integer msgBaiduTemplateId) {
        if (NumberUtil.isNullOrZero(msgBaiduTemplateId)) {
            return null;
        }
        return msgBaiduTemplateDAO.findById(msgBaiduTemplateId);
    }

    @Override
    public MsgBaiduTemplate findByTemplateId(Integer templateId) {
        if (NumberUtil.isNullOrZero(templateId)) {
            return null;
        }
        return msgBaiduTemplateDAO.findByTemplateId(templateId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer insert(MsgBaiduTemplate msgBaiduTemplate) {
        if (Objects.isNull(msgBaiduTemplate)) {
            return GlobalConsts.NONE;
        }
        this.deleteByTemplateId(msgBaiduTemplate.getTemplateId());
        return msgBaiduTemplateDAO.insert(msgBaiduTemplate);
    }

    @Override
    public Integer deleteByTemplateId(Integer templateId) {
        if (NumberUtil.isNullOrZero(templateId)) {
            return GlobalConsts.NONE;
        }
        return msgBaiduTemplateDAO.deleteByTemplateId(templateId);
    }
}
